package com.jike.noobmoney.mvp.presenter;


import com.jike.noobmoney.entity.BannerEntity;
import com.jike.noobmoney.entity.BaseEntity;
import com.jike.noobmoney.entity.CateListEntity;
import com.jike.noobmoney.entity.DownloadUrlEntity;
import com.jike.noobmoney.entity.GoldPromotionEntity;
import com.jike.noobmoney.entity.MyPushDetailEntity;
import com.jike.noobmoney.entity.MyPushEntity;
import com.jike.noobmoney.entity.MyTaskEntity;
import com.jike.noobmoney.entity.NewEntity;
import com.jike.noobmoney.entity.OrderMoneyEntity;
import com.jike.noobmoney.entity.ProByCateEntity;
import com.jike.noobmoney.entity.ShenHeDetailEntity;
import com.jike.noobmoney.entity.ShenHeEntity;
import com.jike.noobmoney.entity.TaskListEntity;
import com.jike.noobmoney.entity.TaskMoneyEntity;
import com.jike.noobmoney.entity.TuosuInfo;
import com.jike.noobmoney.net.BaseSubscriber;
import com.jike.noobmoney.net.IView;


/**
 * 任务
 */
public class TaskPresenter extends BasePresenter<IView> {

    public TaskPresenter(IView view) {
        super(view);
    }

    /**
     * 首页轮播图
     */
    public void getBanner(final String type) {

        addSubscription(iHttpUrl.getBanner(), new BaseSubscriber<BannerEntity>() {
            @Override
            public void onNext(BannerEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity.getHome(), type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }


    /**
     * 任务分类
     */
    public void getCatelist(final String type) {
        addSubscription(iHttpUrl.catelist(), new BaseSubscriber<CateListEntity>() {
            @Override
            public void onNext(CateListEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity.getCatelist(), type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }

    /**
     * 任务大厅列表
     */
    public void getTasklist(String userid, String c_id, String page, String pagesize,String sortclasses,String sorttype, final String type) {
        addSubscription(iHttpUrl.getTaskList(userid, c_id, page, pagesize,sortclasses,sorttype), new BaseSubscriber<TaskListEntity>() {
            @Override
            public void onNext(TaskListEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity.getTask(), type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }

    /**
     * 结果列表页
     */
    public void getSearchTasklist(String userid, String text,  final String type) {
        addSubscription(iHttpUrl.getSearchTaskList(userid, text), new BaseSubscriber<TaskListEntity>() {
            @Override
            public void onNext(TaskListEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity.getTask(), type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }

    /**
     * 根据分类获取属性
     */
    public void getProByCate(String c_id,final String type) {
        addSubscription(iHttpUrl.getPropertyByCate(c_id), new BaseSubscriber<ProByCateEntity>() {
            @Override
            public void onNext(ProByCateEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity, type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }

    /**
     * 官方推荐
     */
    public void getTuijianlist(String userid, String page, String pagesize, final String type) {
        addSubscription(iHttpUrl.getTuiJianList(userid, page, pagesize), new BaseSubscriber<TaskListEntity>() {
            @Override
            public void onNext(TaskListEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity.getTask(), type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }

    /**
     * 公告列表
     */
    public void getNewlist(String userid, String page, String pagesize, final String type) {
        addSubscription(iHttpUrl.getNewList(page, pagesize), new BaseSubscriber<NewEntity>() {
            @Override
            public void onNext(NewEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity.getMessage(), type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }



    /**
     * 最新推荐
     */
    public void getGuanfangList(String userid, String page, String pagesize, final String type) {
        addSubscription(iHttpUrl.getGuanfangList(userid, page, pagesize), new BaseSubscriber<TaskListEntity>() {
            @Override
            public void onNext(TaskListEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity.getTask(), type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }


    /**
     * 今日推荐
     */
    public void getJinRiList(String u_id, String c_id, String page, String pagesize, final String type) {
        addSubscription(iHttpUrl.getJinRiList(u_id, c_id, page, pagesize), new BaseSubscriber<TaskListEntity>() {
            @Override
            public void onNext(TaskListEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity.getTask(), type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }


    /**
     * 发布任务
     */
    public void pushTask(String u_id, int c_id, String taskname, double money,
                         int number, boolean istop, String text, String image, final String type) {
        addSubscription(iHttpUrl.pushTask(u_id, c_id, taskname, money, number, istop ? "1" : "0", text, image), new BaseSubscriber<BaseEntity>() {
            @Override
            public void onNext(BaseEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity.getRinfo(), type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }

    public void pushTask2(String u_id, int c_id, String taskname, double money,
                          int number, boolean istop, String text, String opentype, String openurl,
                          String step, final String type) {
        addSubscription(iHttpUrl.pushTask2(u_id, c_id, taskname, money,
                number, istop ? "1" : "0", text,
                opentype, openurl, step), new BaseSubscriber<BaseEntity>() {
            @Override
            public void onNext(BaseEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity.getRinfo(), type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }
    public void pushTask3(String t_id,String u_id, int c_id, String taskname, double money,
                          int number, boolean istop, String text, String opentype, String openurl,
                          String step, final String type) {
        addSubscription(iHttpUrl.pushTask3(t_id,u_id, c_id, taskname, money,
                number, istop ? "1" : "0", text,
                opentype, openurl, step), new BaseSubscriber<BaseEntity>() {
            @Override
            public void onNext(BaseEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity.getRinfo(), type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }
    //新的发布任务
    public void pushTaskLast(String u_id, int c_id, String taskname,String title, double money,
                          int number,String text, boolean istop,  String opentype, String openurl,
                          String step,boolean isinfo,String isrepeat, String limittime_id1,String limittime_id2,String limittime_id3,String sign,final String type) {
        addSubscription(iHttpUrl.pushTaskLast(u_id, c_id, taskname,title, money,
                number,text, istop ? "1" : "0",
                opentype, openurl, step,isinfo ? "1" : "0",isrepeat,limittime_id1,limittime_id2,limittime_id3,sign), new BaseSubscriber<BaseEntity>() {
            @Override
            public void onNext(BaseEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity.getRinfo(), type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }
    //新的修改任务
    public void pushTaskUpdateLast(String t_id,String u_id, int c_id, String taskname,String title, double money,
                             int number,String text, boolean istop,  String opentype, String openurl,
                             String step,boolean isinfo,String isrepeat, String limittime_id1,String limittime_id2,String limittime_id3,String sign,final String type) {
        addSubscription(iHttpUrl.pushTaskUpateLast(t_id,u_id, c_id, taskname,title, money,
                number,text, istop ? "1" : "0",
                opentype, openurl, step,isinfo ? "1" : "0",isrepeat,limittime_id1,limittime_id2,limittime_id3,sign), new BaseSubscriber<BaseEntity>() {
            @Override
            public void onNext(BaseEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity.getRinfo(), type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }

    /**
     * 我的任务
     */
    public void getMyTask(String u_id, String status, final String type) {
        addSubscription(iHttpUrl.getMyTask(u_id, status), new BaseSubscriber<MyTaskEntity>() {
            @Override
            public void onNext(MyTaskEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity.getOrderlist(), type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }

    /**
     * 我的发布
     */
    public void getMyPush(String u_id, String status, String page, String pageSize, final String type) {
        addSubscription(iHttpUrl.getMyPush(u_id, status, page, pageSize), new BaseSubscriber<MyPushEntity>() {
            @Override
            public void onNext(MyPushEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity.getTask(), type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }

    /**
     * 退款
     */
    public void tuikuan(String t_id, final String type) {
        addSubscription(iHttpUrl.tuikuan(t_id), new BaseSubscriber<BaseEntity>() {
            @Override
            public void onNext(BaseEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity.getRinfo(), type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }

    /**
     * 加票
     */
    public void jiapiao(String t_id, String number, final String type) {
        addSubscription(iHttpUrl.jiapiao(t_id, number), new BaseSubscriber<BaseEntity>() {
            @Override
            public void onNext(BaseEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity.getRinfo(), type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }
    /**
     * 上架
     */
    public void up(String t_id, final String type) {
        addSubscription(iHttpUrl.up(t_id), new BaseSubscriber<BaseEntity>() {
            @Override
            public void onNext(BaseEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity.getRinfo(), type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }
    /**
     * 下架
     */
    public void down(String t_id,  final String type) {
        addSubscription(iHttpUrl.down(t_id), new BaseSubscriber<BaseEntity>() {
            @Override
            public void onNext(BaseEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity.getRinfo(), type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }

    /**
     * 置顶
     */
    public void top(String t_id, String number, final String type) {
        addSubscription(iHttpUrl.top(t_id, number), new BaseSubscriber<BaseEntity>() {
            @Override
            public void onNext(BaseEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity.getRinfo(), type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }




    /**
     * 下载的链接
     */
    public void showUrl(String t_id, final String type) {
        addSubscription(iHttpUrl.showUrl(t_id), new BaseSubscriber<DownloadUrlEntity>() {
            @Override
            public void onNext(DownloadUrlEntity entity) {
                iView.onSuccess("100", "success", entity.getFileurl(), type);
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }

    /**
     * 我的发布详情
     */
    public void getMyPushDetail(String t_id, final String type) {
        addSubscription(iHttpUrl.getMyPushDetail(t_id), new BaseSubscriber<MyPushDetailEntity>() {
            @Override
            public void onNext(MyPushDetailEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity, type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }


    /**
     * 审核列表
     */
    public void getShenHeList(String t_id, String status, String page, String pagesize, final String type) {
        addSubscription(iHttpUrl.getShenHeList(t_id, status), new BaseSubscriber<ShenHeEntity>() {
            @Override
            public void onNext(ShenHeEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity.getOrderlist(), type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }

    /**
     * 审核详情
     */
    public void getShenHeDetail(String o_id, final String type) {
        addSubscription(iHttpUrl.getShenHeDetail(o_id), new BaseSubscriber<ShenHeDetailEntity>() {
            @Override
            public void onNext(ShenHeDetailEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity, type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }

    /**
     * 审核通过
     */
    public void shenHeYes(String o_id, String u_id, String sign,final String type) {
        addSubscription(iHttpUrl.shenHeYesNew(o_id, u_id,sign), new BaseSubscriber<BaseEntity>() {

            @Override
            public void onNext(BaseEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity, type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }

    /**
     * 审核不通过
     */
    public void shenHeNo(String o_id, String yuanyin, final String type) {
        addSubscription(iHttpUrl.shenHeNo(o_id, yuanyin), new BaseSubscriber<BaseEntity>() {
            @Override
            public void onNext(BaseEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity, type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }


    /**
     * 投诉举报
     */
    public void tousu(String o_id, String yuanyin, final String type) {
        addSubscription(iHttpUrl.tousu(o_id, yuanyin), new BaseSubscriber<BaseEntity>() {
            @Override
            public void onNext(BaseEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity, type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }

    /**
     * 1.发布者排行榜
     */
    public void getPushList(String mouth, String stype, final String type) {
        String url = "0".equals(mouth) ? "renwu/taskweekrankapi" : "renwu/commissionmonthrankapi";
        addSubscription(iHttpUrl.getPushListNew(url, stype), new BaseSubscriber<TaskMoneyEntity>() {
            @Override
            public void onNext(TaskMoneyEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), "0".equals(mouth) ? entity.getTaskweekrank() : entity.getCommissionmonthrank(), type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }

    /**
     * 2.投手
     */
    public void getOrderList(String stype, final String type) {
        addSubscription(iHttpUrl.getOrderListNew(stype), new BaseSubscriber<OrderMoneyEntity>() {
            @Override
            public void onNext(OrderMoneyEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity.getOrderweekrank(), type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }


    /**
     * 3.发布者排行榜
     */
    public void getInviteList(String mouth, String stype, final String type) {
        String url = "0".equals(mouth) ? "renwu/inviteweekrankapi" : "renwu/invitemonthrankapi";
        addSubscription(iHttpUrl.getInviteListNew(url, stype), new BaseSubscriber<GoldPromotionEntity>() {
            @Override
            public void onNext(GoldPromotionEntity entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), "0".equals(mouth) ? entity.getInviteweekrank() : entity.getInvitemonthrank(), type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }


    public void appealinfo(String o_id, final String type) {
        addSubscription(iHttpUrl.getAppealinfo(o_id), new BaseSubscriber<TuosuInfo>() {
            @Override
            public void onNext(TuosuInfo entity) {
                if ("100".equals(entity.getCode())) {
                    iView.onSuccess(entity.getCode(), entity.getRinfo(), entity.getAppeal(), type);
                } else {
                    iView.onFailed(entity.getCode(), entity.getRinfo());
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }



}
